from domain import CharMeta
from zhipuai import ZhipuAI


class PlayGenerator:
    def __init__(self, char_meta: CharMeta):
        self.client = ZhipuAI(api_key="01020b6e3f0b99db1641a08661198d4a.8zeaLRZ03xyf949h", )
        self.meta = char_meta
        self.name = char_meta['bot_name']
        self.messages = []

    def invoke(self, input: str):
        self.messages.append({'role': 'user','content': input})
        response = self.client.chat.completions.create(
            model='charglm-3',
            meta=self.meta,
            messages=self.messages
        )
        message = response.choices[0].message
        self.messages.append({'role': 'assistant','content': message.content})
        return message
